package com.es.esapi.common;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;

@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CommonResponse<T> {
    private  Integer code;
    private  String message;
    private  T data;
    protected  CommonResponse(Integer code,String message ,T data){

        this.code=code;
        this.message=message;
        this.data=data;
    }

    public static<T> CommonResponse <T> createForSuccess(){

        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDescription(), null);
    }
    public static<T> CommonResponse <T> createForSuccess(T data){

        return new CommonResponse<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getDescription(), data);
    }
    public static<T> CommonResponse <T> createForError(){

        return new CommonResponse<>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getDescription(), null);
    }
    public static<T> CommonResponse <T> createForError(String message){

        return new CommonResponse<>(ResponseCode.ERROR.getCode(), message, null);
    }
    public static<T> CommonResponse <T> createForError(Integer code, String message){

        return new CommonResponse<>(code, message, null);
    }
    @JsonIgnore
    public  boolean isSuccess(){
        return  this.code== ResponseCode.SUCCESS.getCode();
    }


}
